/*
 * @Author: wuqingchun
 * @Date: 2024-10-16 16:38:57
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-10-31 20:44:34
 */
#ifndef __LIBNET_H__
#define __LIBNET_H__

#include <cstddef>
#include <cstdint>

/**
 * @brief TCP 客户端回调处理接口类定义
 * 
 */
class INetTCPClientCallback
{
public:
    virtual void OnConnected() = 0;
    virtual void OnDisconnected() = 0;
    virtual void OnMessage(const void* pData, size_t ulDataLen) = 0;
};

class INetTCPConnection
{
public:
    virtual ~INetTCPConnection()
    {

    }

    virtual int GetFd() = 0;
    virtual int32_t DealRDEvent() = 0;
    virtual int32_t DealWREvent() = 0;
    virtual int32_t DealERREvent() = 0;
    virtual int32_t Send(const void* pData, size_t ulDataLen) = 0;
    virtual void Close() = 0;
};

class INetTCPConnectionCallback
{
public:
    virtual ~INetTCPConnectionCallback()
    {

    }

    virtual void OnConnected(INetTCPConnection *pobjConn) = 0;
    virtual void OnDisconnected(INetTCPConnection *pobjConn) = 0;
    virtual void OnMessage(const void* pData, size_t ulDataLen) = 0;
};


/**
 * @brief TCP 客户端接口类定义
 * 
 */
class INetTCPClient
{
public:
    virtual ~INetTCPClient()
    {
        
    }

    virtual int32_t Start() = 0;
    virtual void Stop() = 0;
    virtual int32_t SendMessage(const void* pData, size_t ulDataLen) = 0;
};

class INetTCPServer
{
public:
    virtual ~INetTCPServer()
    {
        
    }

    virtual int32_t Start() = 0;
    virtual void Stop() = 0;
};

// 导出函数

extern INetTCPClient* NewTCPClient(INetTCPConnectionCallback* pobjCallback, const char* pcHost, uint16_t usPort);
extern void DeleteTCPClient(INetTCPClient* pobjClient);

class INetEventHandler;
extern INetTCPServer* NewTCPServer(INetEventHandler* pobjEventHandler, INetTCPConnectionCallback* pobjCallback, const char* pcHost, uint16_t usPort);
extern void DeleteTCPServer(INetTCPServer* pobjServer);

#endif //__LIBNET_H__